// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import VoteList from './components/VoteList'
import MyInfo from './components/MyInfo'
import Login from './components/Login'
import { XHeader, AlertPlugin, ToastPlugin, LoadingPlugin, ConfirmPlugin } from 'vux'
import store from './store'
import VueScroller from 'vue-scroller'
import VueLazyload from 'vue-lazyload'
import VueClipboard from 'vue-clipboard2'

Vue.component('x-header', XHeader)
Vue.use(VueScroller)
Vue.use(VueClipboard)
Vue.use(VueRouter)
Vue.use(AlertPlugin)
Vue.use(LoadingPlugin)
Vue.use(ToastPlugin)
Vue.use(ConfirmPlugin)
Vue.use(VueLazyload, {
  preLoad: 1,
  error: require('./assets/nopicture.png'),
  loading: require('./assets/loading.gif'),
  attempt: 2
})

Vue.config.devtools = true

const routes = [
  {
    name: 'login',
    path: '/',
    component: Login,
    meta: { title: '视频投票 - 登录' }
  },
  {
    name: 'vote_list',
    path: '/vote_list',
    component: VoteList,
    meta: { title: '视频投票 - 投票列表' }
  },
  {
    name: 'my_info',
    path: '/my_info',
    component: MyInfo,
    meta: { title: '视频投票 - 我的' }
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
FastClick.attach(document.body)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app-box')
